package com.mo.controller;

import com.github.pagehelper.PageInfo;
import com.mo.model.TClueRemark;
import com.mo.query.ClueRemarkQuery;
import com.mo.result.R;
import com.mo.service.ClueRemarkService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author mo
 * version
 */
@RestController
public class ClueRemarkController {

    @Resource
    private ClueRemarkService clueRemarkService;

    @PostMapping("/api/clue/remark")
    //前端用对象形式传，这里变成json数据格式要用@RequestBody来接受，转成java对象
    public R addClueRemark(@RequestBody ClueRemarkQuery clueRemarkQuery){
        int save=clueRemarkService.saveClueRemark(clueRemarkQuery);
        return save>=1?R.OK():R.FAIL();

    }
    @GetMapping("/api/clue/remark")
    //因为式get请求，所以参数都是在url路径里的，所以用@RequestParam来接收
    public R getClueRemark(@RequestParam(value = "current", required = false) Integer current,
                           @RequestParam(value = "clueId") Integer clueId){
        ClueRemarkQuery clueRemarkQuery = new ClueRemarkQuery();
        clueRemarkQuery.setClueId(clueId);
        if (current==null){
            current=1;
        }
        PageInfo<TClueRemark> pageInfo = clueRemarkService.getClueRemarkByPage(current,clueRemarkQuery);
        return  R.OK(pageInfo);
    }
    @GetMapping("/api/clue/remark/{id}")
    public R clueRemarkEdit(@PathVariable Integer id){
        TClueRemark clueRemark= clueRemarkService.getClueRemarkById(id);
        return R.OK(clueRemark);
    }
    @PutMapping("/api/clue/remark/edit")
    //前端用对象形式传，这里变成json数据格式要用@RequestBody来接受，转成java对象
    public R editClueRemark(@RequestBody ClueRemarkQuery clueRemarkQuery){
        int update=clueRemarkService.updateClueRemark(clueRemarkQuery);
        return update>=1?R.OK():R.FAIL();
    }

    @DeleteMapping(value = "/api/clue/remark/{id}")
    public R delActivityRemark(@PathVariable(value = "id") Integer id){
        int del=clueRemarkService.delAClueRemarkById(id);
        return del>=1?R.OK():R.FAIL();
    }
}
